Amplify Gen2 で作成した DynamoDB のパーティションキーを任意の名称に変更する方法を教えてください

Amplify Gen2 で作成した DynamoDB のパーティションキーを任意の名称に変更する方法を教えてください

Clock Icon2024.09.10

困っていた内容

Amplify のドキュメントを参考に Amplify Gen2 で DynamoDB を作成しましたが、パーティションキーの名称が id で固定されています。

パーティションキーの名称を変更する方法を教えてください。

どう対応すればいいの?

identifier() メソッドを使用してください。

Amplify ドキュメントより

Identifiers are defined using the .identifier() method on a model definition. Usage of the .identifier() method is optional; when it's not present, the model will automatically have a field called id of type ID that is automatically generated unless manually specified.

ドキュメントでは以下の例が紹介されていますので、ご要件に合わせてパーティションキーの名称を変更してください。

const schema = a.schema({
  Todo: a.model({
    todoId: a.id().required(),
    content: a.string(),
    completed: a.boolean(),
  })
  .identifier(['todoId'])
  .authorization(allow => [allow.publicApiKey()]),
});

参考資料

この記事をシェアする

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.